/**
 * @Author: ***
 * @Description: token
 * @Version: 1.0.0
 * @Date: 2023/12/04 22:39
 */

package sw_auth

import (
	"github.com/golang-jwt/jwt/v4"
)

const (
	SECRET = "sw2Devcomisapowerfulmicroservicearchitectureupgradedandoptimizedfromacommercialproject"
)

type Token struct {
	jwt.RegisteredClaims
	TenantId  string `json:"tenant_id"`
	UserName  string `json:"user_name"`
	RealName  string `json:"real_name"`
	UserIdx   string `json:"user_idx"`
	TokenType string `json:"token_type"`
	RoleName  string `json:"role_name"`
	Uid       string `json:"uid"`
	UserId    string `json:"user_id"`
	RoleId    string `json:"role_id"`
	JwtUuid   string `json:"jwt_uuid"`
	Name      string `json:"name"`
	Account   string `json:"account"`
	ClientId  string `json:"client_id"`
}

func ParseToken(secret string, token string) (tokenInfo *Token, err error) {
	tokenInfo = &Token{}
	_, err = jwt.ParseWithClaims(token, tokenInfo, func(token *jwt.Token) (interface{}, error) {
		return []byte(secret), nil
	})
	return
}
